package cn.ilikes.modules.likes.modules.users.impls;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.springframework.stereotype.Component;

import cn.ilikes.modules.likes.dbs.IlikesUser;
import cn.ilikes.modules.likes.modules.IlikesHbaseService;
import cn.ilikes.modules.likes.modules.users.IUserService;
import cn.ilikes.modules.likes.modules.users.IlikesUserException;
import cn.ilikes.tools.hbase.clients.HbaseClientServiceException;
import cn.ilikes.tools.logs.Loggerfactory;

@Component(IUserService.SPRING_SERVICE)
public class UserServiceImpl implements IUserService {

	private Logger logger = Loggerfactory.instance(UserServiceImpl.class);

	@Resource(name = IlikesHbaseService.SPRING_SERVICE)
	private IlikesHbaseService hbaseIlikesService;

	@Override
	public void regUser(IlikesUser userInfo) throws IlikesUserException {

		try {
			Loggerfactory.debug(logger, "reg user : " + userInfo);
			hbaseIlikesService.save(userInfo);
		} catch (HbaseClientServiceException e) {
			Loggerfactory.error(logger, "reg user info  " + userInfo, e);
			throw new IlikesUserException(e);
		}
	}

	@Override
	public IlikesUser getIlikesUser(String key) throws IlikesUserException {

		try {
			return hbaseIlikesService.get(key, IlikesUser.class);
		} catch (HbaseClientServiceException e) {
			Loggerfactory.error(logger, "get  user info  " + key, e);
			throw new IlikesUserException(e);
		}
	}

	@Override
	public void removeUser(IlikesUser userInfo) throws IlikesUserException {
		try {
			hbaseIlikesService.delect(userInfo);
		} catch (HbaseClientServiceException e) {
			Loggerfactory.error(logger, "remove user no success   : " + userInfo.getLoginName(), e);
			throw new IlikesUserException(e);
		}
	}

	@Override
	public void update(IlikesUser userInfo) throws IlikesUserException {
		hbaseIlikesService.update(userInfo);
		
	}

}
